/**
 * Created by xiao++ on 7/13/16.
 */
import alt from '../alt';

class UploadFileActions {
    /**
     * 注册actions到strore中,每个action对应store的一个onActionName的函数.
     *
     */
    constructor() {
        this.generateActions(
            'addFormSuccess',
            'addFormFail',
            'updatePic',
            'updateFile',
            'updateAge',
            'updateSex'
        );
    }

    /**
     * 这里Ajax获取到数据以后将结果传给actions,然后store的对应bindAction的监听函数(onActionName)就会拿到.
     *
     */
    addForm(pic, file, age, sex) {
        console.info('提交form');
        $.ajax({
            url: '/api/addform',
            type: 'post',
            data:{
                pic: pic,
                file: file,
                age: age,
                sex: sex
            }
        }).done((data) => {
            this.actions.addFormSuccess(data)
        }).fail((jqXhr) => {
            this.actions.addFormFail(jqXhr)
        });
    }
}

export default alt.createActions(UploadFileActions);